package com.maiji.cloud.entities.community;

import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.Table;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import com.google.common.collect.Lists;
import com.maiji.cloud.entities.login.UploadRecord;
import com.maiji.cloud.entities.login.UserInfo;
import com.maiji.cloud.response.login.UserInfoResData;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldIndex;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.ArrayList;
import java.util.List;

@NoArgsConstructor
@Data
@Accessors(chain=true)
@Table(name = "com_msg_info")
@Document(indexName = "community",type = "com_msg_info")
public class ComMsgInfo implements Comparable{

    @Id
    @Field(index = FieldIndex.no)
    @TableId
    @Column(name = "msg_id", type = MySqlTypeConstant.VARCHAR, length = 50, isKey = true)
    private String msgId;

    @Field(index = FieldIndex.no)
    @Column(name = "user_id", type = MySqlTypeConstant.VARCHAR, length = 50)
    private String userId;

    @Field(index = FieldIndex.analyzed,analyzer = "ik_smart",searchAnalyzer = "ik_smart")
    @Column(name = "title", type = MySqlTypeConstant.VARCHAR,length = 50)
    private String title;

    @Field(index = FieldIndex.analyzed,analyzer = "ik_smart",searchAnalyzer = "ik_smart")
    @Column(name = "content", type = MySqlTypeConstant.TEXT)
    private String content;

    @Column(name = "publish_time", type = MySqlTypeConstant.BIGINT)
    private Long publishTime;//发布时间戳

    @Column(name = "type",type = MySqlTypeConstant.INT,length = 2)
    private Integer type; //类型. 0：文本，1：图片 2：视频

    @Column(name = "show_location",type = MySqlTypeConstant.INT,length = 2,defaultValue = "0")
    private Boolean showLocation; //是否展示地理位置。 0：否 1：是

    @Column(name = "only_mine",type = MySqlTypeConstant.INT,length = 2,defaultValue = "0")
    private Boolean onlyMine; //仅自己可见。 0：否 1：是

    @Column(name = "commented_count", type = MySqlTypeConstant.INT, length = 2,defaultValue = "0")
    private Integer commented_count; //评论过数量（只增不减，删除评论不影响此值，可以作为评论多页显示的页码）

    @Column(name = "comment_count", type = MySqlTypeConstant.INT, length = 2,defaultValue = "0")
    private Integer comment_count; //保留的评论数量

    @Column(name = "priority" , type = MySqlTypeConstant.INT, length = 2,defaultValue = "0")
    private Integer priority; //优先级 0：普通动态，1：推荐动态，2：精品动态（客服选出），3：案例

    @Column(name = "page_view" , type = MySqlTypeConstant.INT, length = 4,defaultValue = "0")
    @TableField(value = "page_view")
    private Integer pu;//访问量

    @Column(name = "praise_count" , type = MySqlTypeConstant.INT, length = 4,defaultValue = "0")
    private Integer praise_count;//点赞

    @Column(name = "transmit_count" , type = MySqlTypeConstant.INT, length = 4,defaultValue = "0")
    private Integer transmit_count;//转发

    @Column(name = "collect_count" , type = MySqlTypeConstant.INT, length = 4,defaultValue = "0")
    private Integer collect_count;//收藏

    @Column(name = "location_id",type = MySqlTypeConstant.VARCHAR, length = 50)
    private String locationId;//地点

    @Column(name = "delete",type = MySqlTypeConstant.INT,length = 2,defaultValue = "0")
    private Integer delete;//1：被用户删除 、2：被管理员删除 3：被隔离

    @Column(name = "is_top",type = MySqlTypeConstant.INT,length = 2,defaultValue = "0")
    private Integer isTop;//是否置顶

    @Column(name = "top_sort",type = MySqlTypeConstant.INT,length = 2,defaultValue = "0")
    private Integer topSort;//置顶排序

    @Column(name = "is_integral",type = MySqlTypeConstant.INT,length = 2,defaultValue = "0")
    private Integer isIntegral;//是否转发得积分 0 ：否 1 ：是

    @Column(name = "integral",type = MySqlTypeConstant.INT,length = 2)
    private Integer integral;//积分数值

    @Column(name = "restart_day",type = MySqlTypeConstant.INT,length = 2)
    private Integer restartDay;//转发重置周期

    @Column(name = "is_report",type = MySqlTypeConstant.INT,length = 2,defaultValue = "0")
    private Integer isReport;//是否举报

    @Column(name = "report_count" , type = MySqlTypeConstant.INT, length = 4,defaultValue = "0")
    private Integer report_count;//举报数量

    @Column(name = "examined" , type = MySqlTypeConstant.INT, length = 1)
    private Integer examined;  //是否审核, 0-未审核，1-自动审核，2-人工审核

    @Column(name = "isolation", type = MySqlTypeConstant.BIT)
    private Boolean isolation; //是否隔离 ， 是 ： 仅发布人可见

    @TableField(exist = false)
    private String act; //话题搜索
    @TableField(exist = false)
    private String nickName; //发布者昵称
    @TableField(exist = false)
    private Long allCCCount;  //全部评论数量
    @TableField(exist = false)
    private Long notReadCount;  //未读评论数量
    @TableField(exist = false)
    private UserInfo userInfo;//用户信息
    @TableField(exist = false)
    private ArrayList<UploadRecord> uploadRecords;//资源文件
    @TableField(exist = false)
    private ArrayList<ComUserRelation> userRelations;//粉丝关注关系
    @TableField(exist = false)
    private ComPraise praise;//访问用户是否点赞
    @TableField(exist = false)
    private ComMsgCollect collect;//访问用户是否收藏
    @TableField(exist = false)
    private ArrayList<ComPraise> praises;//点赞记录
    @TableField(exist = false)
    private ArrayList<ComMsgCollect> msgCollects;//收藏记录
    @TableField(exist = false)
    private ComLocationInfo locationInfo;//地点
    @TableField(exist = false)
    private List<ComComment> comments;//评论记录
    @TableField(exist = false)
    private List<ComMsgTransmit> msgTransmits;//用户转发关系
    @TableField(exist = false)
    private List<ComAtWho> atUserIds; //at列表
    @TableField(exist = false)
    private UserInfoResData user;
    @TableField(exist = false)
    private List<Long> publishTimes;
    @TableField(exist = false)
    private List<ComMiddleLabel> labels;
    @TableField(exist = false)
    private ComMiddleLabel label;
    @TableField(exist = false)
    private List<Integer> labelIds = Lists.newArrayList();
    @TableField(exist = false)
    private List<ComMiddleActivity> acts;
    @TableField(exist = false)
    private String realmName;
    @TableField(exist = false)
    private String webUrl = "/pages/communityDetail/communityDetail?uuId=";

    public String getWebUrl() {
        return realmName + webUrl + msgId;
    }

    public void setLabelIds (List labelIds) {
        if (labelIds != null) this.labelIds = labelIds;
    }

    @Override
    public int compareTo(Object obj) {
        ComMsgInfo msg = (ComMsgInfo) obj;
        if (this.isTop != msg.isTop) return msg.isTop - this.isTop;
        else if (this.topSort != msg.topSort) return this.topSort - msg.topSort;
        else if (this.label.getIsTop() != msg.label.getIsTop())
            return msg.label.getIsTop() - this.label.getIsTop();
        else return this.label.getTopSort() - msg.label.getTopSort();
    }

}
